package com.cjbdi.service;
import java.util.List;

import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.cjbdi.dao.UserSubscribeRepository;
import com.cjbdi.entity.UserSubscribe;
import com.cjbdi.entity.UserGonggao;
import com.cjbdi.pagination.PageInfo;

@Service
@Transactional
public class UserSubscribeService {
	@Autowired
    private UserSubscribeRepository subscribeRepository;

    public void save(UserSubscribe subscribe) {
    	subscribeRepository.save(subscribe);

    }


	public PageInfo<UserSubscribe> getPageByParam(String status,String fymc,String sfunction,Pageable pageable){
		Page<UserSubscribe> page = subscribeRepository.getPageByParam(status, fymc, sfunction, pageable);
		int records = (int) page.getTotalElements();
        int pageSize = page.getSize();
        int total = records % pageSize == 0 ? records / pageSize : records / pageSize + 1;
        PageInfo<UserSubscribe> pageInfo = new PageInfo<>();
        pageInfo.setPage(page.getNumber() + 1);//页码
        pageInfo.setPageSize(pageSize);//页面大小
        pageInfo.setRows(page.getContent());//分页结果
        pageInfo.setRecords(records);//总记录数
        pageInfo.setTotal(total);//总页数
		return pageInfo;
	}
	
	public List<UserSubscribe> getSubscribeByid(int id){
    	return subscribeRepository.getSubscribeByid(id);
	}
	
}
